home *** CD-ROM | disk | FTP | other *** search
- /************************************************************/
- /* */
- /* CMouse Code from Chapter Six of */
- /* */
- /* *** The Macintosh Programming Primer *** */
- /* */
- /* Copyright 1990, Dave Mark */
- /* */
- /* This program demonstrates specific Mac programming */
- /* techniques. */
- /* */
- /************************************************************/
-
- #include "CMouse.h"
-
-
- /******************************** IMouse *********/
-
- void CMouse::IMouse( int strID, int objWidth, int objHeight,
- Point hitPt, Rect theLoc, CPanorama *theRama )
- {
- LongRect r;
-
- IMouseTask( strID );
-
- thePanorama = theRama;
- theLocation = theLoc; /* The current location of the gray rect. */
-
- /* We'll use theBounds to restrict the gray rect's movement, so the
- DragPane will be restricted to the bounds of the panorama. */
-
- thePanorama->GetBounds(&r);
- r.left += hitPt.h;
- r.top += hitPt.v;
- r.right -= (objWidth - hitPt.h);
- r.bottom -= (objHeight - hitPt.v);
- /*theBounds = r;OLD*/
- LongToQDRect( &r, &theBounds );
- }
-
-
- /******************************** BeginTracking *********/
-
- void CMouse::BeginTracking( struct LongPt *startPt )
- {
- Rect r;
-
- PenMode( patXor );
- PenPat( gray );
-
- r = theLocation;
- FrameRect( &r );
- }
-
-
- /******************************** KeepTracking *********/
-
- void CMouse::KeepTracking( struct LongPt *currPt, struct LongPt *prevPt,
- struct LongPt *startPt )
- {
- LongRect r, f;
- Rect shortR;
- long curTicks;
- LongPt startPosit, newPosit, cp, pp;
- RgnHandle clipRgn;
-
- thePanorama->GetPosition( &startPosit );
-
- clipRgn = NewRgn();
-
- if ( thePanorama->AutoScroll( currPt )
- || ! EqualLongPt( currPt, prevPt ) )
- {
- thePanorama->GetPosition( &newPosit );
-
- GetClip( clipRgn );
- QDToLongRect( &((**clipRgn).rgnBBox), &r );
- OffsetLongRect( &r, startPosit.h - newPosit.h,
- startPosit.v - newPosit.v );
-
- thePanorama->GetFrame(&f);
- PinInRect(&f, (LongPt *)(&(r.top)));
- PinInRect(&f, (LongPt *)(&(r.bottom)));
-
- LongToQDRect( &r, &shortR );
- ClipRect( &shortR );
-
- shortR = theLocation; /* Erase old gray rect */
-
- curTicks = TickCount();
- while ( curTicks == TickCount() ) ;
- FrameRect( &shortR );
- QDToLongRect( &shortR, &r );
-
- cp = *currPt;
- pp = *prevPt;
- QDToLongRect( &theBounds, &f );
- PinInRect(&f, &cp);
- PinInRect(&f, &pp);
-
- OffsetLongRect(&r, cp.h - pp.h, cp.v - pp.v);
-
- SetClip( clipRgn );
-
- curTicks = TickCount();
- while ( curTicks == TickCount() ) ;
-
- LongToQDRect( &r, &shortR );
- FrameRect( &shortR ); /* Draw new gray rect */
- theLocation = shortR; /* update theLocation instance var */
- }
-
- DisposeRgn( clipRgn );
- }
-
-
- /******************************** EndTracking *********/
-
- void CMouse::EndTracking( struct LongPt *currPt, struct LongPt *prevPt,
- struct LongPt *startPt )
- {
- Rect r;
-
- r = theLocation;
- FrameRect( &r );
- PenNormal();
- }
-
-
- /******************************** GetLocation *********/
-
- void CMouse::GetLocation( Rect *theLoc )
- {
- *theLoc = theLocation;
- }